import React, {PureComponent, Fragment} from 'react';
import styles from './index.less';
import Zan from "@/assets/images/bonceChatGpt/unZan.png";
import Cai from "@/assets/images/bonceChatGpt/unCai.png";
import Zaned from "@/assets/images/bonceChatGpt/zan.png";
import Caied from "@/assets/images/bonceChatGpt/cai.png";

class zanOrCai extends PureComponent {
  constructor(props) {
    super(props);
    this.state={
      feedback:"",
      msgVisible:false,
      type:props.islike || "",
      showType:props.islike || "",
    }
  }
  handleClickZan=(type)=>{
    this.setState({
      type:type
    })
    try {
      this.submitFeedback(type)
    } catch (error) {
      console.log(error);
    }
  }
  submitFeedback=(type)=>{
    const { dispatch,resp ,question,index,} = this.props;
    const status = this.props?.predictStatus||false
    dispatch({
      type: 'intellectAssistant/fetchFeedBack',
      payload: {
          answer:JSON.stringify(resp),
          question,
          islike:type,
          feedback:"",
          index,
          qa_flag: status ?"0":"1"
      },
      callback: () => {
        this.setState({
          showType: type
        });
      },
    });
  }
  stopClick=()=>{
    const { changeStatus,stop} = this.props
    const status= !stop
    changeStatus(status)
  }
  render() {
      const { createTime,stop} = this.props
    return <Fragment>
      <div className={styles.zanPage}>
        <div className={styles.createTime}>
          <div>{createTime}</div>
          <div className={styles.stop}  onClick={this.stopClick}>  {stop?"重新生成":"停止生成"}</div>
        </div>
          <div className={styles.caiOrZan}>
            <img
              src={this.state.showType === '1' ? Zaned : Zan}
              alt=""
              onClick={() => {
                this.handleClickZan(
                  '1'
                );
              }}
            />
            <img
              src={this.state.showType === '0' ? Caied : Cai}
              alt=""
              onClick={() => {
                this.handleClickZan(
                  '0'
                )
              }}
            />
          </div>
      </div>
    </Fragment>
  }
}

export default zanOrCai
